{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f503d3ec",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/jerryjliu/llama_index/blob/main/docs/examples/llm/langchain.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "343d5ee5-c78d-493d-9df9-2d170dbd71d9",
   "metadata": {},
   "source": [
    "## LangChain LLM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "703e0586-723b-4a32-81c3-96c1054a998d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.llms import OpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "911bb011-40b3-44d7-9d99-6a0e8a193753",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.llms import LangChainLLM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1470203e-80fd-4013-af89-b2b5ad80a14d",
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = LangChainLLM(llm=OpenAI())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59ae3b49-4f62-4248-b2d8-4ec3ab04f7e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "response_gen = llm.stream_complete(\"Hi this is\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cb35c1e-a04b-4526-ad8c-ddf6e37e9fd2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " a test\n",
      "\n",
      "Hello! Welcome to the test. What would you like to learn about?"
     ]
    }
   ],
   "source": [
    "for delta in response_gen:\n",
    "    print(delta.delta, end=\"\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
